const http=require('http')

const server=http.createServer()

server.on('request',(req,res)=>{
    // console.log(req.url)
    // res.setHeader('Content-Type','text/html;charset=utf-8')
    // res.end('哈喽')
    const url=req.url
    let content='404'
    if(url=='/'||url=='/index.html'){
        content='Hello World NodeJS'
    }else if(url=='/news.html'){
        content='新闻中心1'
    }
//  设置响应头
    res.setHeader('Content-Type','text/html;charset=utf-8')
    res.end(content)


})

server.listen(3001,()=>{
    console.log('服务器启动成功，请访问http://127.0.0.1')
})